package com.starinside.wp.repository;

import com.starinside.wp.domain.ChildrenHealthBaseInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * *******************************
 * Created by Tim.
 * form com.matt
 * on 2017/11/1
 * *******************************
 */
@Repository
public interface ChildrenHealthBaseInfoRepository extends JpaRepository<ChildrenHealthBaseInfo, String>, JpaSpecificationExecutor<ChildrenHealthBaseInfo> {

    List<ChildrenHealthBaseInfo> findByChildrenIdOrderByCreatedDesc(String childrenId);

    Page<ChildrenHealthBaseInfo> findAllByChildrenIdOrderByCreatedDesc(String childrenId, Pageable pageable);

    @Query("select i from ChildrenHealthBaseInfo i where i.childrenId=:childrenId and i.evaluateTime >= :beginDate and i.evaluateTime<=:endDate and i.physicalHeight IS NOT NULL and i.physicalWeight IS NOT NULL order by i.evaluateTime ")
    List<ChildrenHealthBaseInfo> findByChildrenIdAndEvaluateTimeBetween(@Param("childrenId") String childrenId, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
}
